<template>
    <view>
        <z-paging
            ref="paging"
            :refresher-out-rate="0.8"
            :show-empty-view-reload-when-error="false"
            :empty-view-img-style="{ width: '308rpx', height: '308rpx' }"
            empty-view-error-img="https://oneredhealth.oss-cn-hangzhou.aliyuncs.com/2023/10/12/1c53b8aed0c74201bb092265803a1d48.png"
            empty-view-img="https://oneredhealth.oss-cn-hangzhou.aliyuncs.com/2023/10/12/987eadb1d50949a0a7e25dbbd99abe30.png"
            empty-view-error-text="暂无数据"
            bg-color="#FFF"
            v-model="dataList"
            @query="queryList"
        >
            <view slot="top">
                <view class="search" v-if="styleFirstNum == 2">
                    <u-search
                        placeholder="请输入话题"
                        v-model="keyword"
                        bgColor="#F6F6F6"
                        color="#333"
                        placeholderColor="#999999"
                        clearabled
                        height="64rpx"
                        @custom="keywordSearch"
                        :actionStyle="actionStyle"
                    />
                </view>
                <view
                    class="flex_wrap row_between row_middle"
                    v-else
                    style="padding: 30rpx"
                >
                    <u-icon
                        name="https://oneredhealth.oss-cn-hangzhou.aliyuncs.com/2023/09/28/f3a97013cf124649ad85e6955f6ca338.png"
                        size="40rpx"
                        label="更多内容"
                        labelSize="36rpx"
                        labelColor="#3D3D3D"
                    />
                </view>
            </view>
            <view style="padding: 0 40rpx">
                <view
                    v-for="(item, index) in dataList"
                    :key="index"
                    @click="to_counsellingsDetail(item.id)"
                >
                    <view class="news_detail flex_wrap row_between">
                        <u-image
                            height="136rpx"
                            width="240rpx"
                            :src="item.videoCover"
                            mode="aspectFill"
                            radius="8rpx"
                        />
                        <view style="flex: 1; padding-left: 12rpx">
                            <text class="detail_t">{{ item.videoIntro }}</text>
                            <u-text
                                :text="
                                    $u.timeFormat(
                                        item.uploadTime,
                                        'yyyy年mm月dd日'
                                    )
                                "
                                size="24rpx"
                                color="#666"
                                margin="26rpx 0 0 0"
                            />
                        </view>
                    </view>
                </view>
            </view>
        </z-paging>
    </view>
</template>

<script>
import caches from "@/config/caches.js";
import {
    getVideoCounselling,
    getVideoCounsellingLogin,
} from "@/api/enterprise.js";
import { baseUrl } from "@/config/tendIdConfig";
export default {
    data() {
        return {
            actionStyle: {
                fontSize: "28rpx",
                color: "#333",
            },
            keyword: "",
            title: {
                marginLeft: "12rpx",
            },
            dataList: [],
            videoTypeId: "",
            styleFirstNum: "",
        };
    },
    onLoad(options) {
        console.log(options, "gengduo");
        this.videoTypeId = options.videoTypeId;
        this.styleFirstNum = options.styleFirstNum;
        options.tag && (this.keyword = options.tag);
    },
    methods: {
        keywordSearch() {
            this.$refs.paging.reload();
        },

        async queryList(pageNo, pageSize) {
            if (this.styleFirstNum == 2) {
                const params = {
                    pageNum: pageNo,
                    pageSize: pageSize,
                    recordType: 1,
                    healthMaster: 1,
                    tag: this.keyword,
                };
                this.getPersonInfo(params);
            } else {
                const data = {
                    pageNum: pageNo,
                    pageSize: pageSize,
                    videoTypeId: this.videoTypeId,
                    tenantId: this.$tendId,
                };
                this.getVideoList(data);
            }
        },
        async getPersonInfo(params) {
            const result = uni.getStorageSync(caches.ACCESS_TOKEN)
                ? await getVideoCounsellingLogin(params)
                : await getVideoCounselling(params);
            this.$refs.paging.completeByTotal(
                result.data?.rows,
                result.data.total
            );
        },
        to_counsellingsDetail(id, styleFirstNum) {
            if (this.styleFirstNum == 0 || this.styleFirstNum == 1) {
                this.$u.route({
                    url: "/pages_consultation/counsellings/ichrTextDetails",
                    params: {
                        id,
                        styleFirstNum: this.styleFirstNum,
                    },
                });
            } else {
                console.log("1111");
                this.$u.route({
                    url: "/pages_consultation/counsellings/detailsSalesman",
                    params: {
                        id,
                    },
                });
            }
        },
        getVideoList(data) {
            const token =
                this.$store.getters?.customer_token ||
                uni.getStorageSync("customer_token");
            const that = this;
            uni.request({
                url:
                    baseUrl +
                    "/customer/video_info_customer/open/pageVideoNoToken",
                method: "POST",
                header: {
                    Authorization: token,
                },
                data,
                success(res) {
                    // const result = res.data.data?.rows ?? [];
                    that.$refs.paging.completeByTotal(
                        res.data.data?.rows,
                        res.data.data?.total
                    );
                },
            });
        },
    },
};
</script>

<style lang="scss" scoped>
.search {
    padding: 32rpx 28rpx;
}
.cellBox {
    padding: 24rpx 28rpx;
}

.detail {
    padding: 20rpx;
}

.upload {
    width: 154rpx;
    height: 60rpx;
    background: #f3f9ff;
    border-radius: 4000rpx 4000rpx 4000rpx 4000rpx;
}
.news_detail {
    padding: 24rpx 0 3rpx;
}

.detail_t {
    display: block;
    width: 412rpx;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    font-size: 28rpx;
    color: #3d3d3d;
}
</style>
